package com.bjyhl.medical.main.video;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bjyhl.ui.recycler.DataConverter;
import com.bjyhl.ui.recycler.ItemType;
import com.bjyhl.ui.recycler.MultipleFields;
import com.bjyhl.ui.recycler.MultipleItemEntity;

import java.util.ArrayList;

/**
 * 新闻列表
 */
public class VideoCategoryListDataConverter extends DataConverter {
    @Override
    public ArrayList<MultipleItemEntity> convert() {
        final JSONArray dataArray = JSON.parseObject(getJsonData()).getJSONArray("data");

        final int size = dataArray.size();
        for (int i = 0; i < size; i++) {
            final JSONObject data = dataArray.getJSONObject(i);

            final String title = data.getString("title");
            final String content = data.getString("m3u8_name");

            int type = ItemType.VIDEO;
            final MultipleItemEntity entity = MultipleItemEntity.builder()
                    .setField(MultipleFields.ITEM_TYPE, type)
                    .setField(MultipleFields.CONTENT, content)
                    .setField(MultipleFields.TITLE, title)
                    .build();
            ENTITIES.add(entity);
        }

        return ENTITIES;
    }
}
